
//
//  ALPPlayListViewController.m
//  AlpFM
//
//  Created by KING on 16/2/27.
//  Copyright © 2016年 Alp. All rights reserved.
//

#import "ALPPlayListViewController.h"
#import "ALPPlayListTableViewCell.h"
#import "ALPPlayViewController.h"
@interface ALPPlayListViewController ()
<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *myTableView;
@end

@implementation ALPPlayListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //标题
    UILabel *label =[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
    label.text = @"音乐列表";
    label.textAlignment = NSTextAlignmentCenter;
//    label.backgroundColor = CLEAR;
    self.navigationItem.titleView = label;
    
    
    //取消按钮
    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"btn_cancel_h@2x.png"]];
    imgView.frame = CGRectMake(0, 0, 0.13*SCREEN_WIDTH, 0.07*SCREEN_WIDTH);
    imgView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rightBarButtonAction:)];
    [imgView addGestureRecognizer:tap];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:imgView];
//    self.navigationItem.leftBarButtonItem.tintColor = COLOR_SELECTED;
    
    //    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonAction:)];
    
    
    
    //铺cell
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.view addSubview:self.myTableView];
    
    [self.myTableView registerClass:[ALPPlayListTableViewCell class] forCellReuseIdentifier:@"lol"];
}
#pragma mark - 取消按钮
- (void)rightBarButtonAction:(UIBarButtonItem *)btn{
    
    [self dismissViewControllerAnimated:YES completion:^{
    }];
    
}

#pragma mark - 协议方法 高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 0.16*SCREEN_WIDTH;
}

#pragma mark - 协议方法 行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.listArray.count;
}

#pragma mark - 协议方法 cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ALPPlayListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"lol"];
    
    cell.model = [self.listArray objectAtIndex:indexPath.row];
    cell.alpha = 0.6;
    return cell;
}

#pragma mark - 进入播放页面
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //取消选中置灰
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    
    ALPPlayViewController *player = [ALPPlayViewController sharePlayerViewController];
    ALPSingleModel *model = [self.listArray objectAtIndex:indexPath.row];
    player.song_ID = model.trackId.intValue;      //歌曲的ID
    player.allMusicArray = self.listArray;//歌曲数组
    player.indexRow = indexPath.row;     //点击的歌曲的下标
    
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
